@extends('public.father')

@section('content')
    <!-- TAB NAVIGATION -->
    <ul class="nav nav-tabs" role="tablist">
        <li class="active"><a href="javascript:;">文章列表</a></li>
        <li><a href="/article/create">添加文章</a></li>
    </ul>
    <table class="table table-hover">
        <thead>
        <tr>
            <th>ID</th>
            <th>文章内容</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
       @foreach($article as $v)
            <tr>
                <td>{{$v['id']}}</td>
                <td>{{mb_substr($v['content'],0,40)}}...</td>
                <td>
                    <div class="btn-group">
                        <a href="/article/{{$v['id']}}/edit" class="btn btn-success">编辑</a>
                        <a href="javascript:;" onclick="remove({{$v['id']}})" class="btn btn-danger">删除</a>
                    </div>
                </td>
            </tr>
       @endforeach
        </tbody>
            <script>
            function remove(id){
                layui.use('layer', function(){
                    if (confirm("确定删除该文章吗?")){
                        var _token = "{{csrf_token()}}"
                        $.ajax({
                            url:'/article/destroy/'+id,
                            method:'DELETE',
                            data:{_token:_token},
                            success: function(res){
                                console.log(res)
                                if(res.valid == 1){
                                        layer.open({
                                            title: '消息提示'
                                            ,content: res.message
                                        });
                                    setTimeout( "location.reload()",1500)
                                }
                            }
                        })
                    }
                });
            }
        </script>
    </table>
    {{ $article->links() }}
@endsection